//
//  NProblemTableViewQuestionCell.m
//  nncloud
//
//  Created by gdy on 2018/9/26.
//  Copyright © 2018年 youedata. All rights reserved.
//

#import "NProblemTableViewQuestionCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSDate+Extension.h"

@interface NProblemTableViewQuestionCell()

@property(nonatomic, strong) UIImageView *iconImageView;
@property(nonatomic, strong) UILabel *nameLb;
@property(nonatomic, strong) UILabel *timeLb;

@property(nonatomic, strong) UIImageView *bgImageView;
@property(nonatomic, strong) UILabel *progressLb;
@property(nonatomic, strong) UILabel *contentLb;


@end

@implementation NProblemTableViewQuestionCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = 0;
        self.iconImageView = [UIImageView new];
        [self.contentView addSubview:self.iconImageView];
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(@10);
            make.size.mas_equalTo(CGSizeMake(30, 30));
            make.top.mas_equalTo(@5);
        }];
        
        self.nameLb = [UILabel new];
        self.nameLb.textColor = NColorFrom16RGB(cNameColor);
        [self.contentView addSubview:self.nameLb];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconImageView.mas_right).mas_offset(@5);
            make.top.equalTo(self.iconImageView);
            make.height.equalTo(self.iconImageView.mas_height);
            make.right.mas_equalTo(@-100);
        }];
        
        self.timeLb = [UILabel new];
        self.timeLb.font = [UIFont systemFontOfSize:14];
        self.timeLb.textColor = NColorFrom16RGB(cTimeColor);
        [self.contentView addSubview:self.timeLb];
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconImageView);
            make.right.mas_equalTo(@-10);
            make.height.equalTo(self.iconImageView.mas_height);
        }];
        
        
        self.bgImageView = [UIImageView new];
//        self.bgImageView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:self.bgImageView];
        [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconImageView.mas_left);
            make.right.mas_equalTo(@-10);
            make.bottom.mas_equalTo(@-10);
            make.top.mas_equalTo(self.iconImageView.mas_bottom).mas_offset(@5);
        }];
        self.bgImageView.image = [[UIImage imageNamed:@"气泡"] resizableImageWithCapInsets:UIEdgeInsetsMake( 10, 10, 5, 5) resizingMode:UIImageResizingModeStretch] ;
//
        self.progressLb = [UILabel new];
        self.progressLb.font = [UIFont systemFontOfSize:14];
        self.progressLb.textColor = [UIColor redColor];
        [self.bgImageView addSubview:self.progressLb];
        [self.progressLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgImageView).mas_offset(@5);
            make.top.mas_equalTo(@10);
            make.right.mas_equalTo(@0);
            make.height.mas_equalTo(@30);
        }];

        self.contentLb = [UILabel new];
        self.contentLb.textColor = NColorFrom16RGB(cContentColor);
        self.contentLb.numberOfLines = 0;
        self.contentLb.font = [UIFont systemFontOfSize:14];
        [self.bgImageView addSubview:self.contentLb];
        [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.progressLb);
            make.top.equalTo(self.progressLb.mas_bottom);
            make.bottom.mas_equalTo(@-10);
            make.right.equalTo(self.bgImageView);
        }];
        
    }
    return self;
}
- (void)setModel:(NProblemModel *)model
{
    _model = model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.questionUserUrl] placeholderImage:[UIImage imageNamed:@"kefu"]];
    self.iconImageView.layer.cornerRadius = 15.f;
    self.iconImageView.layer.masksToBounds = YES;
    self.nameLb.text = model.questionUserName;
    self.timeLb.text = [NSDate timeTransfer:model.questionCreateTime];
    
    NSArray *arr = [model.questionContent componentsSeparatedByString:@"】"];
    
    if ([arr count] > 1) {
        self.progressLb.textColor = [NProblemModel getProgressColorWithProgress:model.questionProgress];
        self.progressLb.text = [NSString stringWithFormat:@"%@】",[arr objectAtIndex:0]];
        self.contentLb.text = [arr objectAtIndex:1];
    }
//    self.progressLb.text = @"进度进度进度进度进度进度";
//    self.contentLb.text = @"高磊逐渐解开了心中的疑惑······为了赶第二天的早班飞机，家住北京丰台区的高磊（化名）9月12日通过滴滴平台，预约了一辆13日早上6点出发至北京首都国际机场的出租车。不过，当第二天司机打电话告诉他车已到楼下时，他却惊奇地在平台上发现，预约的出租车此时仍距离自己40公里。\n尽管心中满是疑惑，但为了赶时间，他还是坐上了这辆不知从何处开来的出租车。在行驶途中，透过司机的讲述，高磊逐渐解开了心中的疑惑······";
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
